﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public class AB50Data : BaseFunction
    {


        public AB50Data()
            : base()
        {

        }

        public AB50Data(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetGAAUF(DataSet dsTarget, DataRow dwABPOS)
        {
            string TableName = "GAAUF";
            try
            {

                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT  GAART, GAVAR,GAFARBE,GAKG1,GAKG3 "
                    + "  FROM INTEX.GAAUF  WHERE GASA = '713'"
                + " AND GAAUFKRS = :GAAUFKRS AND GAAUFLFD=:GAAUFLFD AND GAAUFPOS=:GAAUFPOS";
                orlReadCommand.Parameters.Add("GAAUFKRS", OracleType.NVarChar).Value = dwABPOS["ABPAUFKRS"].ToString();
                orlReadCommand.Parameters.Add("GAAUFLFD", OracleType.NVarChar).Value = dwABPOS["ABPAUFLFD"].ToString();
                orlReadCommand.Parameters.Add("GAAUFPOS", OracleType.NVarChar).Value = dwABPOS["ABPAUFPOS"].ToString();
                dsResult = Connect2Proxy(orlReadCommand);
                if (dsResult.Tables.Count > 0)
                {
                    dsResult.Tables[0].TableName = TableName;
                    Queue Q100 = new Queue();
                    Q100.Enqueue("GAKG1");
                    Q100.Enqueue("GAKG3");
                    DivideBy100(dsResult.Tables[TableName], Q100);
                    dsResult.AcceptChanges();
                }
                foreach (DataTable dtTemp in dsResult.Tables)
                {
                    if (dsTarget.Tables.Contains(TableName))
                    {
                        dsTarget.Tables[TableName].Clear();
                    }
                    dsTarget = ImportDataTable(dsTarget, dtTemp);
                }
                dsTarget.AcceptChanges();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); 
            }
            return dsTarget;
        }

        public DataSet GetABFOLGE(DataSet dsTarget, DataRow dwABPOS)
        {
            //SELECT LSNAME1 FROM LIEFDAT WHERE LSLIEFNR='00000099'
            string TableName = "ABFOLGE";
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT distinct ABFAUFKRS,ABFAUFLFD,ABFAUFPOS,ABFLIEFNR,trim(LSNAME1) as LSNAME1 "
                    + "  FROM INTEX." + TableName + " , INTEX.LIEFDAT WHERE  ABFMANDANT = LSMANDANT " +
                    " AND ABFLIEFNR = LSLIEFNR AND TRIM(ABFLIEFNR) IS NOT NULL AND  " +
                " ABFAUFKRS = :ABFAUFKRS AND ABFAUFLFD=:ABFAUFLFD AND ABFAUFPOS=:ABFAUFPOS";
                orlReadCommand.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwABPOS["ABPAUFKRS"].ToString();
                orlReadCommand.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwABPOS["ABPAUFLFD"].ToString();
                orlReadCommand.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = dwABPOS["ABPAUFPOS"].ToString();
                dsResult = Connect2Proxy(orlReadCommand);
                if (dsResult.Tables.Count > 0)
                {
                    dsResult.Tables[0].TableName = TableName;
                }
                byte[] b;
                string value;

                foreach (DataRow rowABFOLGE in dsResult.Tables[TableName].Rows)
                {

                    foreach (DataColumn dc in dsResult.Tables[TableName].Columns)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(rowABFOLGE[dc.ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        rowABFOLGE[dc.ColumnName] = value;
                        if (dc.ColumnName == "LSNAME1")
                        {
                            dwABPOS["FACTORY"] = rowABFOLGE["LSNAME1"];
                            Tracer.Speak("染纱厂：" + value);
                        }
                    }

                }
                /* foreach (DataTable dtTemp in dsResult.Tables)
                 {
                     if (dsTarget.Tables.Contains(TableName))
                     {
                         dsTarget.Tables[TableName].Clear();
                     }
                     dsTarget = ImportDataTable(dsTarget, dtTemp);
                 }
                 dsTarget.AcceptChanges();*/
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); 
            }
            return dsTarget;
        }
        public DataSet GetABPOS(DataSet dsTarget, DataRow dwABPOS)
        {
            // FROM GSDAT A,GSCOLOR B,GSMATK C WHERE A.GSMANDANT = B.GSCMANDANT AND A.GSART = B.GSCART "
            //  +" AND A.GSVAR = B.GSCVAR AND A.GSMANDANT = C.GSMMANDANT AND A.GSART = C.GSMART AND A.GSVAR = C.GSMVAR
            // "SELECT Distinct ABPAUFKRS ,ABPAUFLFD,ABPAUFPOS,ABPART,ABPVAR," +
            //   "ABPSOLLMENGE5/100 AS WEI,ABPFARBE,ABPSTARTDAT,ABPENDDAT,'' as COMMENTS,'' as FACTORY,ABPLTVORL, "
            //   + " '' as USAGE,'' as FABRIC ,'' AS REMARK,'' AS COLOR,'' AS DES, '' AS COMPONENT "
            //   + " FROM INTEX.ABPOS WHERE  ABPAUFART='GP' AND ABPERLKZ <>'J' AND "
            //       + " ABPAUFKRS = :ABPAUFKRS AND ABPAUFLFD=:ABPAUFLFD ";
            string TableName = "ABPOS";
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT Distinct ABPAUFKRS ,TO_NUMBER(ABPAUFLFD) AS FLFD, "
                + " TO_NUMBER(ABPAUFPOS) AS FPOS, ABPART,ABPVAR,GSGARNBEZ,GSCBEZ,ABPAUFLFD,ABPAUFPOS,"
                + " ROUND(ABPSOLLMENGE5/100) AS WEI1,GAKG1/100 AS WEI,ABPFARBE,ABPSTARTDAT,ABPENDDAT,ABPNEUDAT,ABPLTVORL, "
                + " STRAGG(DISTINCT GSMRANT/10||'%'||trim(GSMRSPZ))OVER(PARTITION BY ABPAUFKRS ,ABPAUFLFD,ABPAUFPOS,ABPART, "
                + " ABPVAR,GSGARNBEZ,GSCBEZ,ABPSOLLMENGE5,ABPFARBE,ABPSTARTDAT,ABPENDDAT,ABPNEUDAT,ABPLTVORL) AS COMPONENT,"
                + " STRAGG(DISTINCT ZUSPPART)OVER(PARTITION BY ABPAUFKRS, ABPAUFLFD, ABPAUFPOS, ABPART, ABPVAR,  "
                + " GSGARNBEZ, GSCBEZ, ABPSOLLMENGE5, ABPFARBE, ABPSTARTDAT, ABPENDDAT, ABPLTVORL) AS SPPART, "
                + " '' as COMMENTS,'' as FACTORY, '' as USAGE,'' as FABRIC ,'' AS REMARK,ARWERT*0.001 AS PRICE "
                + " FROM INTEX.ABPOS,GSDAT,GSCOLOR,GSMATK,GAAUF,ABPR,ZUTEI WHERE  ABPAUFART='GP' AND ABPERLKZ <>'J' "
                + " AND ABPMANDANT = ARMANDANT AND ABPAUFKRS = ARAUFKRS AND ABPAUFLFD = ARAUFLFD "
                + " AND ABPAUFPOS = ARAUFPOS AND ARAFOLGE = '000'  "
                + " AND GASA = '713' AND ABPAUFKRS = GAAUFKRS AND ABPAUFLFD = GAAUFLFD AND ABPAUFPOS = GAAUFPOS "
                + " AND ABPMANDANT = GSMANDANT AND ABPART = GSART AND ABPVAR = GSVAR AND ABPMANDANT = GSCMANDANT "
                + " AND ABPART = GSCART AND ABPVAR = GSCVAR AND ABPFARBE = GSCFARBE AND ABPMANDANT = GSMMANDANT "
                + " AND ABPART = GSMART AND ABPVAR = GSMVAR  AND ABPAUFKRS LIKE 'D%' "
                + " AND GAMANDANT = ZUMANDANT(+) AND GAAUFKRS = ZUAUFKRS(+) "
                + " AND GAAUFLFD = ZUAUFLFD(+) AND GAAUFPOS = ZUAUFPOS(+) AND GAART = ZUART(+)  "
                + " AND GAVAR = ZUVAR(+) AND GAFARBE = ZUFARBE(+) "
                + " AND ABPAUFKRS = :ABPAUFKRS AND ABPAUFLFD=:ABPAUFLFD "
                + " order by 3";
                orlReadCommand.Parameters.Add("ABPAUFKRS", OracleType.NVarChar).Value = dwABPOS["ABPAUFKRS"].ToString();
                orlReadCommand.Parameters.Add("ABPAUFLFD", OracleType.NVarChar).Value = dwABPOS["ABPAUFLFD"].ToString();
                dsResult = Connect2Proxy(orlReadCommand);
                if (dsResult.Tables.Count > 0)
                {
                    dsResult.Tables[0].TableName = TableName;
                }
                byte[] b;
                string value;
                foreach (DataRow dw in dsResult.Tables[TableName].Rows)
                {
                    foreach (DataColumn dc in dsResult.Tables[TableName].Columns)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw[dc.ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw[dc.ColumnName] = value;

                    }
                }
                foreach (DataTable dtTemp in dsResult.Tables)
                {
                    DataSet setUI = new DataSet();
                    setUI = ImportDataTable(setUI, dtTemp);
                    DataTable tableABPOS = setUI.Tables["ABPOS"];
                    foreach (DataRow dwTmp in tableABPOS.Rows)
                    {
                        //setUI = GetGSDAT(setUI, dwTmp);
                        setUI = GetABFOLGE(setUI, dwTmp);
                        setUI = GetABAUFM(setUI, dwTmp);
                        string YarnOrder = dwTmp["ABPAUFKRS"].ToString().Trim() + dwTmp["ABPAUFLFD"].ToString().Trim() + dwTmp["ABPAUFLFD"].ToString().Trim();
                        dwTmp["REMARK"] = GetCommentsFromTXTIND("ABP", YarnOrder);
                        Tracer.Speak("生产单：" + YarnOrder + "注意：" + dwTmp["REMARK"].ToString());
                    }

                    if (dsTarget.Tables.Contains(TableName))
                    {
                        dsTarget.Tables[TableName].Clear();
                    }
                    dsTarget = ImportDataTable(dsTarget, setUI.Tables["ABPOS"]);
                }
                dsTarget.AcceptChanges();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); 
            }
            return dsTarget;
        }
        public DataSet GetABAUFM(DataSet dsTarget, DataRow dwABPOS)
        {

            string TableName = "ABAUFM";
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "select a.abaaufkrs,a.abaauflfd,a.abaaufpos,ABPAUFKRS,ABPAUFLFD,ABPAUFPOS, "
                                            + " b.abpwakz,b.ABPART,b.ABPVAR,b.ABPFARBE,'' as USAGE,'' as FABRIC "
                                            + " from abaufm a,abpos b where a.abamandant = b.abpmandant "
                                            + " AND ABAVKAUFKRS=ABPAUFKRS AND ABAVKAUFLFD=ABPAUFLFD AND ABAVKAUFPOS=ABPAUFPOS "
                                            + " and ABAAPOS>'0001' "
                                            + "AND  ABAAUFKRS = :ABAAUFKRS AND ABAAUFLFD=:ABAAUFLFD AND ABPAUFPOS=:ABAAUFPOS";
                orlReadCommand.Parameters.Add("ABAAUFKRS", OracleType.NVarChar).Value = dwABPOS["ABPAUFKRS"].ToString();
                orlReadCommand.Parameters.Add("ABAAUFLFD", OracleType.NVarChar).Value = dwABPOS["ABPAUFLFD"].ToString();
                orlReadCommand.Parameters.Add("ABAAUFPOS", OracleType.NVarChar).Value = dwABPOS["ABPAUFPOS"].ToString();
                dsResult = Connect2Proxy(orlReadCommand);
                if (dsResult.Tables.Count > 0)
                {
                    dsResult.Tables[0].TableName = TableName;

                    /* foreach (DataRow rowABAUFM in dsResult.Tables[TableName].Rows)
                     {
                         dwABPOS["FABRIC"] = rowABAUFM["ABPART"].ToString().Trim() + "-"
                                         + rowABAUFM["ABPFARBE"].ToString().Trim() + "-"
                                         + rowABAUFM["ABPVAR"].ToString().Trim();
                     }*/

                    #region FOUND
                    string usage = "";
                    string fabric = "";

                    foreach (DataRow rowTemp in dsResult.Tables["ABAUFM"].Rows)
                    {
                        if (rowTemp["ABPWAKZ"].ToString() == "R")
                        {
                            usage += "纬纱";
                            fabric += rowTemp["ABPART"].ToString().Trim() + "-"
                                        + rowTemp["ABPFARBE"].ToString().Trim() + "-"
                                        + rowTemp["ABPVAR"].ToString().Trim();
                            Tracer.Speak(fabric + "：" + usage);
                        }
                        else
                        {
                            if (rowTemp["ABPWAKZ"].ToString() == "K")
                            {
                                orlReadCommand = OracleDB.CreateCommand();
                                orlReadCommand.CommandText = "select a.abaaufkrs,a.abaauflfd,a.abaaufpos,b.abpaufkrs,b.abpauflfd,b.abpaufpos, "
                                                            + " b.abpwakz,b.ABPART,b.ABPVAR,b.ABPFARBE,'' as usage,'' as fabric "
                                                            + " from abaufm a,abpos b where a.abamandant = b.abpmandant "
                                                            + " AND ABAVKAUFKRS=ABPAUFKRS AND ABAVKAUFLFD=ABPAUFLFD AND ABAVKAUFPOS=ABPAUFPOS "
                                                            + " and ABAAPOS>'0001' "
                                                            + "AND  ABAAUFKRS = :ABAAUFKRS AND ABAAUFLFD=:ABAAUFLFD AND ABPAUFPOS=:ABAAUFPOS";
                                orlReadCommand.Parameters.Add("ABAAUFKRS", OracleType.NVarChar).Value = rowTemp["ABPAUFKRS"].ToString();
                                orlReadCommand.Parameters.Add("ABAAUFLFD", OracleType.NVarChar).Value = rowTemp["ABPAUFLFD"].ToString();
                                orlReadCommand.Parameters.Add("ABAAUFPOS", OracleType.NVarChar).Value = rowTemp["ABPAUFPOS"].ToString();
                                dsResult = Connect2Proxy(orlReadCommand);
                                //dsResult = new DataSet();
                                if (dsResult.Tables.Count > 0)
                                {

                                    foreach (DataRow rowTemp1 in dsResult.Tables[0].Rows)
                                    {
                                        usage += "经纱";
                                        fabric += rowTemp1["ABPART"].ToString().Trim() + "-"
                                        + rowTemp1["ABPFARBE"].ToString().Trim() + "-"
                                        + rowTemp1["ABPVAR"].ToString().Trim();
                                        Tracer.Speak(fabric + "：" + usage);
                                    }
                                }
                                else
                                {
                                    usage += "";
                                    fabric += "";
                                }

                            }
                            else
                            {
                                if (rowTemp["ABPWAKZ"].ToString() == "G")
                                {
                                    orlReadCommand = OracleDB.CreateCommand();
                                    orlReadCommand.CommandText = "select a.abaaufkrs,a.abaauflfd,a.abaaufpos,b.abpaufkrs,b.abpauflfd,b.abpaufpos, "
                                                                + " b.abpwakz,b.ABPART,b.ABPVAR,b.ABPFARBE,'' as usage,'' as fabric "
                                                                + " from abaufm a,abpos b where a.abamandant = b.abpmandant "
                                                                + " AND ABAVKAUFKRS=ABPAUFKRS AND ABAVKAUFLFD=ABPAUFLFD AND ABAVKAUFPOS=ABPAUFPOS "
                                                                + " and ABAAPOS>'0001' "
                                                                + "AND  ABAAUFKRS = :ABAAUFKRS AND ABAAUFLFD=:ABAAUFLFD AND ABPAUFPOS=:ABAAUFPOS";
                                    orlReadCommand.Parameters.Add("ABAAUFKRS", OracleType.NVarChar).Value = rowTemp["ABPAUFKRS"].ToString();
                                    orlReadCommand.Parameters.Add("ABAAUFLFD", OracleType.NVarChar).Value = rowTemp["ABPAUFLFD"].ToString();
                                    orlReadCommand.Parameters.Add("ABAAUFPOS", OracleType.NVarChar).Value = rowTemp["ABPAUFPOS"].ToString();
                                    dsResult = Connect2Proxy(orlReadCommand);
                                    dsResult = new DataSet();
                                    if (dsResult.Tables.Count > 0)
                                    {
                                        foreach (DataRow rowTemp1 in dsResult.Tables[0].Rows)
                                        {
                                            if (rowTemp1["ABPWAKZ"].ToString() == "R")
                                            {
                                                usage += "纬纱";
                                                fabric += rowTemp1["ABPART"].ToString().Trim() + "-"
                                                            + rowTemp1["ABPFARBE"].ToString().Trim() + "-"
                                                            + rowTemp1["ABPVAR"].ToString().Trim();
                                                Tracer.Speak(fabric + "：" + usage);
                                            }
                                            else
                                            {
                                                if (rowTemp1["ABPWAKZ"].ToString() == "K")
                                                {
                                                    orlReadCommand = OracleDB.CreateCommand();
                                                    orlReadCommand.CommandText = "select a.abaaufkrs,a.abaauflfd,a.abaaufpos,b.abpaufkrs,b.abpauflfd,b.abpaufpos, "
                                                                                + " b.abpwakz,b.ABPART,b.ABPVAR,b.ABPFARBE,'' as usage,'' as fabric "
                                                                                + " from abaufm a,abpos b where a.abamandant = b.abpmandant "
                                                                                + " AND ABAVKAUFKRS=ABPAUFKRS AND ABAVKAUFLFD=ABPAUFLFD AND ABAVKAUFPOS=ABPAUFPOS "
                                                                                + " and ABAAPOS>'0001' "
                                                                                + "AND  ABAAUFKRS = :ABAAUFKRS AND ABAAUFLFD=:ABAAUFLFD AND ABPAUFPOS=:ABAAUFPOS";
                                                    orlReadCommand.Parameters.Add("ABAAUFKRS", OracleType.NVarChar).Value = rowTemp1["ABPAUFKRS"].ToString();
                                                    orlReadCommand.Parameters.Add("ABAAUFLFD", OracleType.NVarChar).Value = rowTemp1["ABPAUFLFD"].ToString();
                                                    orlReadCommand.Parameters.Add("ABAAUFPOS", OracleType.NVarChar).Value = rowTemp1["ABPAUFPOS"].ToString();
                                                    dsResult = Connect2Proxy(orlReadCommand);
                                                    dsResult = new DataSet();
                                                    if (dsResult.Tables.Count > 0)
                                                    {
                                                        foreach (DataRow rowTemp2 in dsResult.Tables[0].Rows)
                                                        {
                                                            usage += "经纱";
                                                            fabric += rowTemp2["ABPART"].ToString().Trim() + "-"
                                                            + rowTemp2["ABPFARBE"].ToString().Trim() + "-"
                                                            + rowTemp2["ABPVAR"].ToString().Trim();
                                                            Tracer.Speak(fabric + "：" + usage);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        usage += "";
                                                        fabric += "";
                                                    }
                                                }
                                            }

                                        }
                                    }
                                    else
                                    {
                                        usage += "";
                                        fabric += "";
                                    }
                                }
                                else
                                {
                                    usage += "";
                                    fabric += "";
                                }

                            }
                        }
                        /*
                                        DataTable tableABAUFM=dsTarget.Tables["ABAUFM"];
                                        string expression = "(ABPWAKZ='R' or ABPWAKZ='K')";
                                        DataRow[] rowFound;
                                        rowFound = tableABAUFM.Select(expression);
                                        string nextABPAUFKRS,nextABPAUFLFD,nextABPAUFPOS;
                                        bool flgFound = false;
                
                                        while (!flgFound)
                                        {
                                            usage="";
                                            #region Found
                                            if (rowFound.Count() > 0)
                                            {
                                                flgFound = true;
                                                foreach(DataRow rowTemp in rowFound)
                                                {
                                                    if(rowTemp["ABPWAKZ"].ToString()=="R")
                                                    {
                                                        if (!usage.Contains("W纱;"))
                                                        {
                                                            usage += "W纱;";
                                                        }
                                                        dwABPOS["FABRIC"] = rowTemp["ABPART"].ToString().Trim()+"-"
                                                            + rowTemp["ABPFARBE"].ToString().Trim() + "-"
                                                            + rowTemp["ABPVAR"].ToString().Trim();
                                                    }
                                                   if(rowTemp["ABPWAKZ"].ToString()=="K")
                                                    {
                                                        if (!usage.Contains("J纱;"))
                                                        {
                                                            usage += "J纱;";
                                                        }
                                                        orlReadCommand.Parameters["ABAAUFKRS"].Value = rowTemp["ABPAUFKRS"].ToString();
                                                        orlReadCommand.Parameters["ABAAUFLFD"].Value = rowTemp["ABPAUFLFD"].ToString();
                                                        orlReadCommand.Parameters["ABAAUFPOS"].Value = rowTemp["ABPAUFPOS"].ToString();
                                                        dsResult = new DataSet();
                                                        dsResult = Connect2Proxy(orlReadCommand);
                                                        if (dsResult.Tables.Count > 0)
                                                        {
                                                            dsResult.Tables[0].TableName = TableName;
                                                        }
                                                        DataRow rowAB55;
                                                       if(dsResult.Tables[0].Rows.Count>0)
                                                       {
                                                           rowAB55 = dsResult.Tables[0].Rows[0];
                                                           dwABPOS["FABRIC"] = rowAB55["ABPART"].ToString().Trim() + "-"
                                                               + rowTemp["ABPFARBE"].ToString().Trim() + "-"
                                                               + rowTemp["ABPVAR"].ToString().Trim();
                                                       }

                                                    }
                                                }
                                                dwABPOS["USAGE"] = usage;

                                            }
                                        }

                                            #endregion
                                            else
                                            {
                                                if (tableABAUFM.Rows.Count == 0)
                                                {
                                                    flgFound = true;
                                                    break;
                                                }
                                                else
                                                {
                                                    foreach (DataRow rowTemp in tableABAUFM.Rows)
                                                    {
                                                        orlReadCommand.Parameters["ABAAUFKRS"].Value = rowTemp["ABPAUFKRS"].ToString();
                                                        orlReadCommand.Parameters["ABAAUFLFD"].Value = rowTemp["ABPAUFLFD"].ToString();
                                                        orlReadCommand.Parameters["ABAAUFPOS"].Value = rowTemp["ABPAUFPOS"].ToString();
                                                        dsResult = new DataSet();
                                                        dsResult = Connect2Proxy(orlReadCommand);
                                                        if (dsResult.Tables.Count > 0)
                                                        {
                                                            dsResult.Tables[0].TableName = TableName;
                                                        }
                                                        dsTarget.Merge(dsResult);
                                                        tableABAUFM = dsTarget.Tables["ABAUFM"];
                                                        rowFound = tableABAUFM.Select(expression);
                                                    }
                                                }
                                            }
                                        }
                                        */
                        rowTemp["USAGE"] = usage;
                        rowTemp["FABRIC"] = fabric;
                    }
                    dwABPOS["USAGE"] = usage;
                    dwABPOS["FABRIC"] = fabric;

                }
                    #endregion


                /* foreach (DataTable dtTemp in dsResult.Tables)
                {
                    if (dsTarget.Tables.Contains(TableName))
                    {
                        dsTarget.Tables[TableName].Clear();
                    }
                    dsTarget = ImportDataTable(dsTarget, dtTemp);
                }
                dsTarget.AcceptChanges();*/
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); 
            }
            return dsTarget;

        }
        public DataSet GetABKOPF(DataSet dsTarget, DataRow dwABPOS)
        {

            string TableName = "ABKOPF";
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT DISTINCT ABKAUFKRS,ABKAUFLFD,HRNNAME,HRDTELH,HRDFAX,ABKAEDAT,'' as COMMENTS"
                    + "  FROM INTEX.HRSTAMM, INTEX." + TableName
                    + " WHERE  HRBENID=ABKARTSB "
                    + " AND ABKAUFKRS = :ABKAUFKRS AND ABKAUFLFD=:ABKAUFLFD";
                orlReadCommand.Parameters.Add("ABKAUFKRS", OracleType.NVarChar).Value = dwABPOS["ABPAUFKRS"].ToString();
                orlReadCommand.Parameters.Add("ABKAUFLFD", OracleType.NVarChar).Value = dwABPOS["ABPAUFLFD"].ToString();
                dsResult = Connect2Proxy(orlReadCommand);
                if (dsResult.Tables.Count > 0)
                {
                    dsResult.Tables[0].TableName = TableName;
                    dsResult.AcceptChanges();
                }
                byte[] b;
                string value;
                foreach (DataRow dw in dsResult.Tables[TableName].Rows)
                {
                    foreach (DataColumn dc in dsResult.Tables[TableName].Columns)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw[dc.ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw[dc.ColumnName] = value;

                    }
                }
                foreach (DataTable dtTemp in dsResult.Tables)
                {
                    foreach (DataRow dwTmp in dtTemp.Rows)
                    {
                        string YarnOrder = dwTmp["ABKAUFKRS"].ToString().Trim() + dwTmp["ABKAUFLFD"].ToString().Trim();
                        dwTmp["COMMENTS"] = GetCommentsFromTXTIND("AB3", YarnOrder);
                    }
                    if (dsTarget.Tables.Contains(TableName))
                    {
                        dsTarget.Tables[TableName].Clear();
                    }
                    dsTarget = ImportDataTable(dsTarget, dtTemp);
                }
                dsTarget.AcceptChanges();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); 
            }
            return dsTarget;
        }
       
        public DataSet BuildAB50Data(DataSet dsTarget, DataRow dwABPOS)
        {
            try
            {
                dsTarget = GetABKOPF(dsTarget, dwABPOS);
                dsTarget = GetABPOS(dsTarget, dwABPOS);
                //dsTarget = GetABAUFM(dsTarget, dwABPOS);
                //dsTarget = GetGAAUF(dsTarget, dwABPOS);
                //dsTarget = GetABFOLGE(dsTarget, dwABPOS);
                //dsTarget = GetGSDAT(dsTarget, dwABPOS);

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex); 
            }
            return dsTarget;
        }
    }
}